package com.chahu.service.impl;

import com.chahu.entity.Snack;
import com.chahu.mapper.FruitMapper;
import com.chahu.service.FruitService;
import com.chahu.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.Collections;
import java.util.List;

public class FruitServiceImpl implements FruitService {

    @Override
    public List<Snack> getFruitList() {
        try (SqlSession sqlSession = MybatisUtil.getFactory().openSession(true)) {
            FruitMapper mapper = sqlSession.getMapper(FruitMapper.class);
            List<Snack> fruitList = null;
            try {
                fruitList = mapper.getFruitList();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return fruitList != null ? fruitList : Collections.emptyList();
        }
    }
}
